

#ifndef _UD_DBID_H
#define _UD_DBID_H 1

#include "zadesk.h"
#include "zdbhandle.h"
#include "ZRXExports.h"
#include "zacarray.h"

#pragma pack(push, 8)

class UcDbDatabase;
class UcDbStub;

class ZRX_DB_EXPORT_STATIC UcDbObjectId
{
public:
    UcDbObjectId();
    UcDbObjectId(const UcDbStub*);

    ZRX_DB_STATIC_EXPORT static const   UcDbObjectId  kNull;

    bool           isNull() const;
    void           setNull();

    ZSoft::IntDbId     asOldId     () const;
    UcDbObjectId&  setFromOldId(ZSoft::IntDbId oldId);
#if defined(_WIN64) || defined(_UC64)
  private:

    UcDbObjectId&  setFromOldId(ZSoft::Int32);

  public:

    inline UcDbObjectId&  setFromOldId(ZSoft::UIntPtr nUnsignedId)
    {
        const ZSoft::IntDbId nSignedId =
                        static_cast<ZSoft::IntDbId>(nUnsignedId);
        return this->setFromOldId(nSignedId);
    }
#endif

    bool           isValid() const;

    UcDbObjectId&  operator =  (const UcDbObjectId&);
    UcDbObjectId&  operator =  (const UcDbStub*);

    bool           operator <  (const UcDbObjectId&) const;
    bool           operator >  (const UcDbObjectId&) const;
    bool           operator >= (const UcDbObjectId&) const;
    bool           operator <= (const UcDbObjectId&) const;
    bool           operator == (const UcDbObjectId&) const;
    bool           operator != (const UcDbObjectId&) const;

    bool           operator <  (const UcDbStub*) const;
    bool           operator >  (const UcDbStub*) const;
    bool           operator >= (const UcDbStub*) const;
    bool           operator <= (const UcDbStub*) const;
    bool           operator == (const UcDbStub*) const;
    bool           operator != (const UcDbStub*) const;

    operator       UcDbStub*   () const;

    UcDbDatabase* database() const;
    UcDbDatabase* originalDatabase() const;
    void          convertToRedirectedId();
    bool          isErased() const;
    bool          isEffectivelyErased() const;
    bool          isResident() const;
    bool          objectLeftOnDisk() const;
    UcDbHandle    handle() const;
    UcDbHandle    nonForwardedHandle() const;

protected:
    UcDbStub*  mId;
};

class UcDbHardOwnershipId : public UcDbObjectId
{
public:
    UcDbHardOwnershipId();
    UcDbHardOwnershipId(const UcDbObjectId&);
    UcDbHardOwnershipId(const UcDbStub*);

    UcDbHardOwnershipId& operator =(const UcDbHardOwnershipId&);
    UcDbHardOwnershipId& operator =(const UcDbObjectId&);
    UcDbHardOwnershipId& operator =(const UcDbStub*);

    bool           operator != (const UcDbObjectId&) const;
    bool           operator != (const UcDbStub*) const;
    bool           operator == (const UcDbObjectId&) const;
    bool           operator == (const UcDbStub*) const;

    operator UcDbStub* () const;
};

class UcDbSoftOwnershipId : public UcDbObjectId
{
public:
    UcDbSoftOwnershipId();
    UcDbSoftOwnershipId(const UcDbObjectId&);
    UcDbSoftOwnershipId(const UcDbStub*);

    UcDbSoftOwnershipId& operator =(const UcDbSoftOwnershipId&);
    UcDbSoftOwnershipId& operator =(const UcDbObjectId&);
    UcDbSoftOwnershipId& operator =(const UcDbStub*);
    bool           operator != (const UcDbObjectId&) const;
    bool           operator != (const UcDbStub*) const;
    bool           operator == (const UcDbObjectId&) const;
    bool           operator == (const UcDbStub*) const;

    operator UcDbStub* () const;
};

class UcDbHardPointerId : public UcDbObjectId
{
public:
    UcDbHardPointerId();
    UcDbHardPointerId(const UcDbObjectId&);
    UcDbHardPointerId(const UcDbStub*);

    UcDbHardPointerId& operator =(const UcDbHardPointerId&);
    UcDbHardPointerId& operator =(const UcDbObjectId&);
    UcDbHardPointerId& operator =(const UcDbStub*);
    bool           operator != (const UcDbObjectId&) const;
    bool           operator != (const UcDbStub*) const;
    bool           operator == (const UcDbObjectId&) const;
    bool           operator == (const UcDbStub*) const;

    operator UcDbStub* () const;
};

class UcDbSoftPointerId : public UcDbObjectId
{
public:
    UcDbSoftPointerId();
    UcDbSoftPointerId(const UcDbObjectId&);
    UcDbSoftPointerId(const UcDbStub*);

    UcDbSoftPointerId& operator =(const UcDbSoftPointerId&);
    UcDbSoftPointerId& operator =(const UcDbObjectId&);
    UcDbSoftPointerId& operator =(const UcDbStub*);
    bool           operator != (const UcDbObjectId&) const;
    bool           operator != (const UcDbStub*) const;
    bool           operator == (const UcDbObjectId&) const;
    bool           operator == (const UcDbStub*) const;

    operator UcDbStub* () const;
};

inline
UcDbObjectId::UcDbObjectId()
{ mId = nullptr; }

inline
UcDbObjectId::UcDbObjectId(const UcDbStub* pStub)
{ mId = const_cast<UcDbStub*>(pStub); }

inline bool
UcDbObjectId::isNull() const
{ return mId == nullptr; }

inline void
UcDbObjectId::setNull()
{ mId = nullptr; }

inline
ZSoft::IntDbId UcDbObjectId::asOldId() const
{
    return reinterpret_cast<ZSoft::IntDbId>(this->mId);
}

inline
UcDbObjectId& UcDbObjectId::setFromOldId(ZSoft::IntDbId oldId)
{
    this->mId = reinterpret_cast<UcDbStub*>(oldId);
    return *this;
}

inline 
UcDbObjectId& UcDbObjectId::operator = (const UcDbObjectId& id)
{ mId = id.mId; return *this; }

inline 
UcDbObjectId& UcDbObjectId::operator = (const UcDbStub* pStub)
{ mId = const_cast<UcDbStub*>(pStub); return *this; }

inline
UcDbObjectId::operator UcDbStub* () const
{ return mId; }

inline
UcDbHardOwnershipId::UcDbHardOwnershipId() {}

inline
UcDbHardOwnershipId::UcDbHardOwnershipId(const UcDbObjectId& id)
  : UcDbObjectId(id) {}

inline
UcDbHardOwnershipId::UcDbHardOwnershipId(const UcDbStub* pStub)
  : UcDbObjectId(pStub) {}

inline
UcDbHardOwnershipId& UcDbHardOwnershipId::operator  = (
    const UcDbHardOwnershipId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline
UcDbHardOwnershipId& UcDbHardOwnershipId::operator = (const UcDbObjectId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline 
UcDbHardOwnershipId& UcDbHardOwnershipId::operator = (const UcDbStub* pStub)
{ mId = const_cast<UcDbStub*>(pStub); return *this; }

inline 
bool UcDbHardOwnershipId::operator != (const UcDbObjectId& id) const
{ return UcDbObjectId::operator!=(id); }

inline 
bool UcDbHardOwnershipId::operator != (const UcDbStub* pStub) const
{ return UcDbObjectId::operator!=(pStub); }

inline 
bool UcDbHardOwnershipId::operator == (const UcDbObjectId& id) const
{ return UcDbObjectId::operator==(id); }

inline 
bool UcDbHardOwnershipId::operator == (const UcDbStub* pStub) const
{ return UcDbObjectId::operator==(pStub); }

inline
UcDbHardOwnershipId::operator UcDbStub* () const
{ return mId; }

inline
UcDbSoftOwnershipId::UcDbSoftOwnershipId() {}

inline
UcDbSoftOwnershipId::UcDbSoftOwnershipId(const UcDbObjectId& id)
  : UcDbObjectId(id) {}

inline
UcDbSoftOwnershipId::UcDbSoftOwnershipId(const UcDbStub* pStub)
  : UcDbObjectId(pStub) {}

inline
UcDbSoftOwnershipId& UcDbSoftOwnershipId::operator = (
    const UcDbSoftOwnershipId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline
UcDbSoftOwnershipId& UcDbSoftOwnershipId::operator = (const UcDbObjectId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline 
UcDbSoftOwnershipId& UcDbSoftOwnershipId::operator = (const UcDbStub* pStub)
{ mId = const_cast<UcDbStub*>(pStub); return *this; }

inline 
bool UcDbSoftOwnershipId::operator != (const UcDbObjectId& id) const
{ return UcDbObjectId::operator!=(id); }

inline 
bool UcDbSoftOwnershipId::operator != (const UcDbStub* pStub) const
{ return UcDbObjectId::operator!=(pStub); }

inline 
bool UcDbSoftOwnershipId::operator == (const UcDbObjectId& id) const
{ return UcDbObjectId::operator==(id); }

inline 
bool UcDbSoftOwnershipId::operator == (const UcDbStub* pStub) const
{ return UcDbObjectId::operator==(pStub); }

inline
UcDbSoftOwnershipId::operator UcDbStub* () const
{ return mId; }

inline
UcDbHardPointerId::UcDbHardPointerId() {}

inline
UcDbHardPointerId::UcDbHardPointerId(const UcDbObjectId& id)
  : UcDbObjectId(id) {}

inline
UcDbHardPointerId::UcDbHardPointerId(const UcDbStub* pStub)
  : UcDbObjectId(pStub) {}

inline
UcDbHardPointerId& UcDbHardPointerId::operator = (
    const UcDbHardPointerId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline
UcDbHardPointerId& UcDbHardPointerId::operator = (const UcDbObjectId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline 
UcDbHardPointerId& UcDbHardPointerId::operator = (const UcDbStub* pStub)
{ mId = const_cast<UcDbStub*>(pStub); return *this; }

inline 
bool UcDbHardPointerId::operator != (const UcDbObjectId& id) const
{ return UcDbObjectId::operator!=(id); }

inline 
bool UcDbHardPointerId::operator != (const UcDbStub* pStub) const
{ return UcDbObjectId::operator!=(pStub); }

inline 
bool UcDbHardPointerId::operator == (const UcDbObjectId& id) const
{ return UcDbObjectId::operator==(id); }

inline 
bool UcDbHardPointerId::operator == (const UcDbStub* pStub) const
{ return UcDbObjectId::operator==(pStub); }

inline
UcDbHardPointerId::operator UcDbStub* () const
{ return mId; }

inline
UcDbSoftPointerId::UcDbSoftPointerId() {}

inline
UcDbSoftPointerId::UcDbSoftPointerId(const UcDbObjectId& id)
  : UcDbObjectId(id) {}

inline
UcDbSoftPointerId::UcDbSoftPointerId(const UcDbStub* pStub)
  : UcDbObjectId(pStub) {}

inline
UcDbSoftPointerId& UcDbSoftPointerId::operator = (const UcDbSoftPointerId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline
UcDbSoftPointerId& UcDbSoftPointerId::operator = (const UcDbObjectId& id)
{ UcDbObjectId::operator=(id); return *this; }

inline 
UcDbSoftPointerId& UcDbSoftPointerId::operator = (const UcDbStub* pStub)
{ mId = const_cast<UcDbStub*>(pStub); return *this; }

inline 
bool UcDbSoftPointerId::operator != (const UcDbObjectId& id) const
{ return UcDbObjectId::operator!=(id); }

inline 
bool UcDbSoftPointerId::operator != (const UcDbStub* pStub) const
{ return UcDbObjectId::operator!=(pStub); }

inline 
bool UcDbSoftPointerId::operator == (const UcDbObjectId& id) const
{ return UcDbObjectId::operator==(id); }

inline 
bool UcDbSoftPointerId::operator == (const UcDbStub* pStub) const
{ return UcDbObjectId::operator==(pStub); }

inline
UcDbSoftPointerId::operator UcDbStub* () const
{ return mId; }

#define ZSOFT_UCDBOBJECTID_DEFINED
#include "zacarrayhelper.h"

#pragma pack(pop)

#endif
